

// 遇到的问题和解决步骤
// 2024年11月8日20:00:28 计算不成功无法选择正确的样品
// ID变更了
this.ProcessProcessCommand("ProcessChain:ea155352-de3a-46ce-bf57-bf3d704fb216", null);


// 1、背景调用
// 在Pki.MolSpec.MSIRInstrumentProxyPlugin的PEInstrumentProxyPlugin构造函数中添加如下代码
// 需要的引用
"SpectrumClient.dll" "MSLiveDisplayBase.dll" "MSLiveScanDisplay.dll"
// 背景
SynchronizationContext synchronizationContext = SynchronizationContext.Current;
SpectrumClient.SocketCient instance = SpectrumClient.SocketCient.Instance;
SpectrumClient.EventBus.ScanBackgroundEvent = delegate ()
{
    synchronizationContext.Post(delegate (object msg)
    {
        this.SendToolClick("QuickScan:ScanBackground");
    }, null);
};
// 2、扫描
SpectrumClient.EventBus.ScanStartEvent = delegate ()
{
    synchronizationContext.Post(delegate (object msg)
    {
        this.SendToolClick("QuickScan:Start");
    }, null);
};

// 3、选择样品
// 在MainForm中的构造函数添加如下方法
public MainForm(AppInfo info)
{
    // ...
    SynchronizationContext synchronizationContext = SynchronizationContext.Current;
    SpectrumClient.SocketCient instance = SpectrumClient.SocketCient.Instance;
    SpectrumClient.EventBus.SampleSelectEvent = delegate ()
    {
        synchronizationContext.Post(delegate (object msg)
        {
            this.AutoSelece();
        }, null);
    };
}


private void AutoSelece()
{
    this.primaryTree.SelectedNodes.Clear();
    this.primaryTree.Nodes[1].Selected = true;
    TreeNodesCollection nodes = this.primaryTree.Nodes[1].Nodes;
    UltraTreeNode ultraTreeNode = nodes[nodes.Count - 1];
    ultraTreeNode.Selected = true;
    if (this.primaryTree.SelectedNodes.Count > 0)
    {
        this.m_TreeNodeSelected = this.primaryTree.SelectedNodes[0];
        IMSPlugin activePlugin = this.m_TreeNodeSelected.Tag as IMSPlugin;
        this.host.ActivePlugin = activePlugin;
        this.primaryTree.Focus();
        UltraTreeNode treeNode = this.GetTreeNode(ultraTreeNode.Key);
        if (treeNode != null)
        {
            treeNode.Selected = true;
            this.primaryTree.ActiveNode = treeNode;
            this.primaryTree.ActiveNode.BringIntoView();
            this.m_TreeNodeSelected = treeNode;
            SpectrumClient.SocketCient.Instance.CacheData = treeNode.Key;
        }
    }
}

// 4、宏计算
// 在Pki.MolSpec.MSGraphSinglePlugin.PEGraphSinglePlugin类的构造函数中添加如下代码
System.Threading.SynchronizationContext synchronizationContext = System.Threading.SynchronizationContext.Current;
SpectrumClient.SocketCient instance = SpectrumClient.SocketCient.Instance;
SpectrumClient.EventBus.SampleCalculateEvent = delegate (string id)
{
    synchronizationContext.Post(delegate (object msg)
    {
        this.ProcessProcessCommand(id, null);
    }, null);
};
// ProcessProcessCommand的70行清空缓存和发布模版id
SpectrumClient.SocketCient.Instance.CacheData = string.Empty;
SpectrumClient.SocketCient.Instance.SendLoop("ProcessId", processID);

// 在Pki.MolSpec.MSGraphPlugin.Curves的GetCurveInfo中507行添加
if (SpectrumClient.SocketCient.Instance.CacheData == namedIDSet2.dataSetId)
{
    namedIDSet2.Selected = CurveSelected.selected;
}

// 5、获取样品计算结果
// 在Pki.MolSpec.MSProcessResults的PEProcessResultsDisplay构造函数中添加如下
System.Threading.SynchronizationContext synchronizationContext = System.Threading.SynchronizationContext.Current;
SocketCient instance = SocketCient.Instance;
EventBus.SampleCalculateResultEvent = delegate ()
{
    synchronizationContext.Post(delegate (object msg)
    {
        instance.SendSampleCalculateResult(SocketCient.Instance.CacheData);
        SocketCient.Instance.CacheData = string.Empty;
    }, null);
};

// 在同类下SaveLayout的第一个if中添加代码
try
{
    List<string> listNmae = new List<string>
                        {
                            "样品名称",
                            "说明",
                            "Cppma",
                            "Oppma"
                        };
    DataRowView dataRowView = (this.resultsGrid.DataSource as DataView)[0];
    StringBuilder stringBuilder = new StringBuilder();
    foreach (object obj in dataRowView.DataView.Table.Columns)
    {
        DataColumn dataColumn = (DataColumn)obj;
        if (listNmae.FindIndex((string p) => dataColumn.ColumnName.StartsWith(p)) >= 0)
        {
            if (stringBuilder.Length > 0)
            {
                stringBuilder.Append(";");
            }
            stringBuilder.Append(string.Format("{0}={1}", dataColumn.ColumnName, dataRowView[dataColumn.ColumnName]));
        }
    }
    SocketCient.Instance.CacheData = stringBuilder.ToString();
}
catch (Exception) { }

// 6、自动删除旧的样品数据 
// 在MainForm中的构造函数添加如下方法，需要先增加 选择样品
EventBus.DeleteTreeNodeEvent = delegate ()
{
    synchronizationContext.Post(delegate (object msg)
    {
        this.DeleteTreeNode();
    }, null);
};
private void DeleteTreeNode()
{
    this.primaryTree.SelectedNodes.Clear();
    this.primaryTree.Nodes[1].Selected = true;
    TreeNodesCollection nodes = this.primaryTree.Nodes[1].Nodes;

    for (int i = 0; i < nodes.Count - 3; i++)
    {
        UltraTreeNode ultraTreeNode = nodes[0];
        ultraTreeNode.Selected = true;
        if (this.primaryTree.SelectedNodes.Count > 0)
        {
            this.m_TreeNodeSelected = this.primaryTree.SelectedNodes[0];
            IMSPlugin activePlugin = this.m_TreeNodeSelected.Tag as IMSPlugin;
            this.host.ActivePlugin = activePlugin;
            this.primaryTree.Focus();
            UltraTreeNode treeNode = this.GetTreeNode(ultraTreeNode.Key);
            if (treeNode != null)
            {
                treeNode.Selected = true;
                this.primaryTree.ActiveNode = treeNode;
                this.primaryTree.ActiveNode.BringIntoView();
                this.m_TreeNodeSelected = treeNode;
            }
        }
        DeletePluginTreeNode();
    }
}

